package com.kunya.product.service.impl.product;

import com.kunya.common.common.ResponseCode;
import com.kunya.common.common.ServerResponse;
import com.kunya.product.dao.product.ProductDetailMapper;
import com.kunya.product.po.ProductDetail;
import com.kunya.product.service.product.IProductDetailService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zp
 * @Description: 商品图文详情接口实现类
 * @date 2018/7/3 13:36
 */
@Service("IProductDetailService")
public class ProductDetailServiceImpl implements IProductDetailService {

    @Autowired
    private ProductDetailMapper productDetailMapper;

    /**
     * @author zp
     * @Description: 插入商品图文详情 ，成功只返回成功状态
     * @param productDetail 商品图文详情实体
     * @param tablePrefix 表前缀
     * @date 2018/7/3 13:44
     */
    public ServerResponse savaProductDetail(ProductDetail productDetail,String tablePrefix){
        if (productDetail==null|| StringUtils.isEmpty(tablePrefix)){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        int resultCount=productDetailMapper.insertSelective(productDetail,tablePrefix);
        if (resultCount<=0){
            return ServerResponse.createByErrorMessage("插入商品图文详情失败");
        }
        return ServerResponse.createBySuccess();
    }

    @Override
    public ServerResponse deleteProductDetailByProductId(Long productId, String tablePrefix) {
        return productDetailMapper.deleteProductDetailByProductId(productId, tablePrefix)==1?
                ServerResponse.createBySuccess("删除商品详情成功"):ServerResponse.createByErrorMessage("删除商品详情失败");
    }
}
